package com.vlh.battleship.server.integration.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import com.vlh.battleship.server.integration.dto.board.EmptyTile;
import com.vlh.battleship.server.integration.dto.board.Tile;
import com.vlh.battleship.server.integration.dto.ship.ShipPiece;

public class TileRowMapper implements ParameterizedRowMapper<Tile>  {

	public Tile mapRow(ResultSet rs, int i) throws SQLException {
		Tile t;
		int tileType = rs.getInt("type");
		if (tileType == 0) {
			t = new EmptyTile();
		} else if (tileType == 0) {
			t = new ShipPiece();
		} else {
			t = new EmptyTile();
		}
		t.setStatus(rs.getInt("status"));
		t.setXPos(rs.getInt("x"));
		t.setYPos(rs.getInt("y"));
		t.setPictureId(rs.getInt("picture_id"));
		return t;
	}

}
